define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'bdl/bd/material/index' + location.search,
                    export_url: 'bdl/bd/material/export',
                    multi_url: 'bdl/bd/material/multi',
                    table: 'bd_material',
                }
            });

            var table       = $("#table");
            var showExport  = $(".btn-export").data('value')

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                search:false,
                fixedColumns: true,
                fixedRightNumber: 1,
                showToggle: false,
                showExport: showExport,
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'forgid', title: __('数据中心/组织'), searchList: function (column) {
                                return Template('forgidtpl', {});
                            }, formatter: function (value, row, index) {
                                return '无';
                            }, visible: false
                        },
                        {field: 'id', title: 'ID'},
                        {field: 'fenable', title: '使用状态', searchList: {"1":'可用',"0":'禁用'}, formatter: Table.api.formatter.status}  ,
                        {field: 'fnumber', title: '编码', operate: 'LIKE'},
                        {field: 'fname', title: '名称', operate: 'LIKE'},

                        {field: 'fk_bdl_isnew', title: '是否新品', searchList: {"1":'是',"2":'否'}, formatter: Table.api.formatter.toggle}  ,
                        {field: 'fk_bdl_ishot', title: '是否热销', searchList: {"1":'是',"2":'否'}, formatter: Table.api.formatter.toggle}  ,
                        {field: 'datacenter.fname', title: '数据中心名称',operate: false},
                        {field: 'forg.fname', title: '组织名称',operate: false},
                        {field: 'forg.fnumber', title: '组织编码',operate: false},
                        {field: 'forg.id', title: '组织ID',operate: false},

                        {field: 'fk_bdl_bdgroup', title: '产品分组ID',visible:false,searchList: $.getJSON("bdl/bd/datacenter/getFilter?type=get_cate_list")},
                        {field: 'cate.fname', title: '产品分组名称',operate: false},

                        {field: 'fk_bdl_unitid', title: '辅助单位', operate: 'LIKE'},
                        {field: 'fk_bdl_priceunitid', title: '基本单位', operate: 'LIKE'},
                        {field: 'fk_bdl_specification', title: '规格描述', operate: 'LIKE'},


                        {field: 'fk_bdl_creatorid', title: '创建人',visible:false,searchList: $.getJSON("bdl/bd/datacenter/getFilter?type=get_admin_list")},
                        {field: 'creator.nickname', title: '创建人', operate: false},
                        {field: 'fk_bdl_createtime', title: '创建时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'fk_bdl_fmodifierid', title: '修改人',visible:false,searchList: $.getJSON("bdl/bd/datacenter/getFilter?type=get_admin_list")},
                        {field: 'modifier.nickname', title: '修改人', operate: false},
                        {field: 'fk_bdl_modifytime', title: '修改时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        edit: function ()
        {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };

    return Controller;
});
